package son.vpoint.dinokids.view;

import org.anddev.andengine.util.MathUtils;

import son.vpoint.dinokids.GameActivity;
import son.vpoint.dinokids.OperatorSelected;
import son.vpoint.dinokids.R;
import son.vpoint.dinokids.until.MathFactory;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.LinearLayout;

public class GameView extends View {
	private GameActivity mActivity;
	private Context context;
	private OperatorSelected mOperatorSelected;
	private int x, y , WIDTH, HEIGTH;
	private Integer[] arrGhimX, arrGhimY;
	public MathFactory mFactory;
	
	public Bitmap mBitmaponCorrect;
	public Bitmap mBitmaponinCorrect;
	public Bitmap[] mBitmapGhim;
	public Paint mPaint;

	public GameView(Context context) {
		super(context);
		mActivity = new GameActivity();
		mFactory = new MathFactory();

	
		mOperatorSelected = new OperatorSelected();

		mBitmapGhim = new Bitmap[5];
		mBitmapGhim[0] = BitmapFactory.decodeResource(getResources(),
				R.drawable.ghim1);
		mBitmapGhim[1] = BitmapFactory.decodeResource(getResources(),
				R.drawable.ghim2);
		mBitmapGhim[2] = BitmapFactory.decodeResource(getResources(),
				R.drawable.ghim3);
		mBitmapGhim[3] = BitmapFactory.decodeResource(getResources(),
				R.drawable.ghim4);
		mBitmapGhim[4] = BitmapFactory.decodeResource(getResources(),
				R.drawable.ghim5);
		mBitmaponCorrect = BitmapFactory.decodeResource(getResources(),
				R.drawable.correct);
		mBitmaponinCorrect = BitmapFactory.decodeResource(getResources(),
				R.drawable.incorrect);
		Typeface mFontNumber = Typeface.createFromAsset(context.getAssets(),
				"fonts/vnibaybuom.ttf");

		mPaint = new Paint();
		mPaint.setColor(Color.WHITE);
		mPaint.setStrokeWidth(50);
		mPaint.setTextSize(200F);
		mPaint.setTypeface(mFontNumber);
		WIDTH = mActivity.getWidth();
		HEIGTH = mActivity.getHeight();
		x = WIDTH/ 10;
		y = 3 * HEIGTH/ 4;
		arrGhimX = new Integer[] { x, 2 * x - x / 6, 3 * x - x / 3,
				4 * x - x / 2, 4 * x + x / 2, 5 * x + x / 2, 6 * x + x / 2,
				7 * x + x / 2, 8 * x + x / 2 };
		arrGhimY = new Integer[] { y - 50, y - 50, y - 50, y - 50, y - 50,
				y - 50, y - 50, y - 50, y - 50 };

	}

	@Override
	protected void onDraw(Canvas canvas) {

		for (int i = 0; i < 9; i++) {
			int k = MathUtils.random(0, 4);
			canvas.drawBitmap(mBitmapGhim[k], arrGhimX[i], arrGhimY[i], mPaint);
		}
//		if (mActivity.onCorrect == true)
//			canvas.drawBitmap(mBitmaponCorrect, x * 5, y * 2 / 3, mPaint);
//		if (mActivity.oninCorrect == true)
//			canvas.drawBitmap(mBitmaponinCorrect, x * 5, y * 2 / 3, mPaint);

		invalidate();
		super.onDraw(canvas);

	}
}
